473,421 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

Unescape escapeXML text

Hi All,

I have an application that is writing Javascript with JSP server side
code that uses escapeXML:

var someVar = "<c:out escapeXml="true" value="You'll never escape!"/
>";
How to I unescape this? Using the unescape() function doesn't cut
it..
unescape("You'll never escape!");

Do I have to use regex to replace or is there some other way?

Thanks for any assistance!

Rob
:)
Oct 14 '08 #1
4 11373
Robert Mark Bram wrote:
I have an application that is writing Javascript with JSP server side
code that uses escapeXML:

var someVar = "<c:out escapeXml="true" value="You'll never escape!"/
";

How to I unescape this? Using the unescape() function doesn't cut
it. unescape("You'll never escape!");

Do I have to use regex to replace or is there some other way?
var txt = 'apostrophe ' / double quote: " / '
+ ' s: s / è: è / Chinese sign: 新';

txt = txt.replace(/(&#)([0-9]{1,5})(;)/g,
function (a1, a2, a3, a4) {
return String.fromCharCode(a3);
}
);
alert(txt);

Hope this helps,

--
Bart
Oct 14 '08 #2
Robert Mark Bram wrote:
Hi All,

I have an application that is writing Javascript with JSP server side
code that uses escapeXML:

var someVar = "<c:out escapeXml="true" value="You'll never escape!"/
>";

How to I unescape this? Using the unescape() function doesn't cut
it..
unescape("You'll never escape!");
Or could escape it differently.

If you are using struts you can use StringEscapeUtils.escapeJavaScript.

Would be really nice to have c:out handle that.

Fictitious example:
<c:out escapeJavaScript="true" value="You'll never escape!"/>

Garrett
>
Rob
:)

--
comp.lang.javascript FAQ <URL: http://jibbering.com/faq/ >
Oct 14 '08 #3
Robert Mark Bram wrote:
I have an application that is writing Javascript with JSP server side
code that uses escapeXML:

var someVar = "<c:out escapeXml="true" value="You'll never escape!"/>";
*g*
How to I unescape this?
Maybe

someVar = someVar.replace(/&lt;/g, "<").replace(/&gt;/g, ">"
.replace(/&amp;/g, "&");
Using the unescape() function doesn't cut it..
unescape("You'll never escape!");
It is not supposed to. unescape() decodes (ASCII) percent-encoded strings.
It was primarily used to decode URI components, and is now deprecated in
favor of decodeURI() and decodeURIComponent(), which in addition can decode
UTF-8 percent encoding.
Do I have to use regex to replace or is there some other way?
A regular expression like above would not help in your case because the
escaping of `"' needs to take place *before* you insert the value with JSP,
i.e. "on the server".

You do not need `escapeXml="true"' if you declare the content of the XHTML
`script' element CDATA, provided the string never contains `"', like
in your example:

<script type="text/javascript">
// <![CDATA[
...
]]>
</script>

But if the `<' and `>' are your only problems, you could as well move the
code to an external script file or simply use HTML instead.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Oct 15 '08 #4
Thanks to all for the input!
Oct 16 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: koen colen | last post by:
Hello group, I hope you guys can help me out, I am modifying a piece of code from Joe Norman, I did found the code here: http://www.intranet2internet.com/public/default.asp?PAGE=sscript&ID=3 ...
2
by: karteikarte | last post by:
hey, i just found this riddle somewhere in the net: <meta http-equiv="Pragma" content="no-cache"> <script language="JavaScript"> <!-- function nstie(){return false}function...
1
by: Harry Keck | last post by:
Is there a set of methods in the .Net framework that do the same thing as the jscript functions escape and unescape? I get very close with HttpUtility.UrlEncodeUnicode, but it puts "+" for...
30
by: mistral | last post by:
Neeed good javascript unescape encoder, to protect javascript code. Some advices? Online tool, or ready javascript only. Any opinions about the Javascript Obfuscator:...
2
by: Richard Lewis Haggard | last post by:
Is it possible to use features from XmlDocument to unescape text back to its original raw text format after it has been escaped to handle non-HTML compliant character strings? I have code that...
2
by: Richard Lewis Haggard | last post by:
Is it possible to use features from XmlDocument to unescape text back to its original raw text format after it has been escaped to handle non-HTML compliant character strings? I have code that...
3
by: mistral | last post by:
How to decrypt this text, what algorithm used to encode text, how to recreate algorithm? %c3%99%c3%a3%c3%af%c3%b3%c3%94%c3%92%c3%89%c3%81%c3%8c%c3%ae%c3%ba...
1
by: RK | last post by:
Perhaps I'm confused somwhere in my understanding, but I'm trying to deal with some escaped text from an XML file which includes html markup and it appears there are a couple of techniques for...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.